#!/bin/bash
# Copyright (C) 2014 Dan Reidy <dubkat@gmail.com>
# http://google.com/+DanReidy
# Pretier portage sync, without the console flooding.
# $Id: port-sync 15 2014-12-22 01:26:24Z dubkat $


test -f /etc/init.d/functions.sh && . /etc/init.d/functions.sh || die "No Functions.sh found."

logger -t port-sync "Starting portage repo sync."

ebegin "Flushing data to disks"
sync
eend $?

einfo "Syncing Overlays ..."
eindent
for repo in `layman -l | awk '{ print $2 }' | xargs -l | sort`; do
	ebegin "$repo"
	layman -s $repo >/dev/null 2>&1
	eend $?
done
eoutdent

ebegin "Syncing master portage tree"
emerge --ignore-default-opts --sync --quiet >/dev/null 2>&1
eend $?

ebegin "Regenerating metadata"
emerge --ignore-default-opts --metadata --quiet >/dev/null 2>&1
eend $?

ebegin "Regenerating EIX cache"
eix-update -q >/dev/null 2>&1
eend $?

ebegin "Flushing data to disk"
sync
eend $?

einfo "Done."

logger -t port-sync "Finished portage repo sync."

